package cn.tedu.luban.attach.main.timer;

import cn.tedu.luban.attach.main.service.AttachService;
import cn.tedu.luban.attach.protocol.query.AttachDeprecatedQuery;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class DeprecatedTimer {
    @Autowired
    private AttachService attachService;

    @Scheduled(cron = "0 0/1 * * * ? ")
    public void deprecatedAttach() {
        AttachDeprecatedQuery attachDeprecatedQuery = new AttachDeprecatedQuery();
        //30分钟之后的 就算作过期删除
        attachDeprecatedQuery.setExpired(new Date().getTime()-1000*60*30);
        int total = attachService.deleteAttachDeprecated(attachDeprecatedQuery);
        log.info("删除过期附件数量:{}",total);
    }
}
